﻿import com.dinmax.isolution.*

class ThemeGUI
extends MovieClip {
	
	private var theme:Theme;
	private var listener:WindowThemesGUI;
	
	function ThemeGUI(){
		if(this._parent._parent instanceof WindowThemesGUI)	this.listener = WindowThemesGUI(this._parent._parent);
		var r:ThemeGUI = this;
		this["mcFavState"].onPress = function():Void {
			r.theme.setFavorite(!r.theme.getFavorite());
			//r.refresh();
			com.dinmax.isolution.HCC.updateServerTheme(r.theme);
			return;
		}
		return;
	}
		
	public function getTheme():Theme{
		return this.theme;
	}
	public function setTheme(newTheme:Theme):Void{
		this.theme = newTheme;
		this.refresh();
		return;
	}
	
	public function setSelected(b:Boolean):Void {
		
		if(b){
			this.gotoAndStop(2);
			this.listener.showThemeView(this.theme);
		
		} else {
			this.gotoAndStop(1);	
		}
		return;
	}
	
	public function getSelected():Boolean{
		return (this._currentframe == 2);
	}
	
	public function refresh():Void {
			
		this["txt_title"].text = this.theme.getName();
		//trace("ThemeGUI | refresh | theme.favorite= "+this.theme.getFavorite());
		this.theme.getFavorite() ? this["mcFavState"].gotoAndStop(2) : this["mcFavState"].gotoAndStop(1);
		
		var mcl:MovieClipLoader = new MovieClipLoader();
		if(this["mcIcon"].img == undefined){
			this["mcIcon"].createEmptyMovieClip("img", 1);
		}
		
		mcl.loadClip(this.theme.getIcon(), this["mcIcon"].img);
		
		return;
	}
	
}